package cn.ekuma.android.ui;

import cn.ekuma.epos.ui.android.R;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;


public class Navigator extends LinearLayout{
	
	public interface NavigatorListener{
	      public void moveFirst();
	      public void movePrev();
	      public void moveNext();
	      public void moveEnd();
	      public void moveTo(int posi);
	}
    
	NavigatorListener l;
	
	Button btnCurrent;
    
	public Navigator(Context context) {
		super(context);
		init(context);
	}
	
	public Navigator(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}
	
    private void init(final Context context) {
    	// ��ȡҳ�沼�� 
        View mainView = LayoutInflater.from(context).inflate( 
                        R.layout.navigator, this); 
        ImageButton btn=(ImageButton) mainView.findViewById(R.id.btnFirst);
        btn.setOnClickListener(new OnClickListener(){

			public void onClick(View v) {
				if(l!=null)
					l.moveFirst();
			}
        });
        
        btn=(ImageButton) mainView.findViewById(R.id.btnPriv);
        btn.setOnClickListener(new OnClickListener(){

			public void onClick(View v) {
				if(l!=null)
					l.movePrev();
			}
        });
        
        btn=(ImageButton) mainView.findViewById(R.id.btnNext);
        btn.setOnClickListener(new OnClickListener(){

			public void onClick(View v) {
				if(l!=null)
					l.moveNext();
			}
        });
        
        btn=(ImageButton) mainView.findViewById(R.id.btnEnd);
        btn.setOnClickListener(new OnClickListener(){

			public void onClick(View v) {
				if(l!=null)
					l.moveEnd();
			}
        }); 
        
        btnCurrent= (Button) mainView.findViewById(R.id.btnCurrent);
    }
    
    
    public void setNavigatorListener(NavigatorListener l){
    	this.l=l;
    }
    
    public void removeNavigatorListener(){
    	this.l=null;
    }
    
    public void setCurrentPageIndex(int current){
    	btnCurrent.setText(String.valueOf(current));
    }
}
